#ifndef _WIN32_CACHE_ENTRY_H
#define _WIN32_CACHE_ENTRY_H

#include "../LibCache.h"
#include <pthread.h>
#include <string>
using namespace std;

LIB_CACHE_NAMESPACE_BEGIN

class Win32CacheManager;
class Win32CacheEntry : public ICacheEntry
{
	friend class Win32CacheManager;
public:
	Win32CacheEntry(const string& basePath);
	virtual ~Win32CacheEntry(void);

	virtual bool Read(byte* buffer, const size_t& bufferSize, size_t& readSize);
	virtual bool Write(const byte* buffer, const size_t& bufferSize, size_t& writeSize);
	virtual bool GetRawBuffer(byte** buffer, size_t& bufferSize) const;
	virtual bool SetRawBuffer(byte* buffer, size_t& bufferSize);
	virtual bool SeekPointer(int position, int begin);
	virtual bool PersistData(const char* path = NULL, bool absolutePath = true) const;
	virtual bool LoadPersistData(const char* path = NULL, bool absolutePath = true);
	virtual size_t GetSize() const;
	virtual bool SetSize(const size_t& size);
	virtual const char* GetName() const;
	virtual bool SetName(const char* name);
	virtual bool Clone(ICacheEntry** cacheEntry) const;
	virtual bool Lock(bool read = true) const;
	virtual bool UnLock() const;
	virtual bool TryLock(bool read = true) const;
	virtual bool IsDirty() const;
	virtual bool CanWrite() const;

private:
	string m_basePath;
	string m_name;
	pthread_rwlock_t* m_rwlock;
	byte* m_buffer;
	size_t m_bufferSize;
	size_t m_dataSize;
	int m_dataPointer;
};

LIB_CACHE_NAMESPACE_END

#endif //_WIN32_CACHE_ENTRY_H
